package ccf201903;

import java.util.Scanner;
import java.util.Stack;

/**
 * 二十四点<br>
 * 
 * 思路：元素不超过9，所以难易程度降低了不少，起码在处理输入过程容易很多，<br>
 * 重点在四则运算上，逆波兰表达式
 * 
 * @author wangxiaonan
 */
public class Q02 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// first line
		int num = sc.nextInt();

		// next lines
		sc.nextLine();
		String[] pokers = new String[num];
		for (int i = 0; i < num; ++i) {
			pokers[i] = sc.nextLine();
		}

		for (int i = 0; i < pokers.length; ++i) {
			int point = calculatePoint(pokers[i]);
			if (point == 24) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}

	private static int calculatePoint(String pokers) {

		// 转换成逆波兰表达式
		char[] chars = pokers.toCharArray();
		Stack<Character> opStack = new Stack<>();
		Stack<Character> coStack = new Stack<>();
		for (int i = 0; i < chars.length; ++i) {
			if (checkChar(chars[i])) {
				coStack.push(chars[i]);
			} else {
				if (opStack.isEmpty()) {
					opStack.push(chars[i]);
				} else if (compareOp(chars[i], opStack.peek().charValue()) <= 0) {
					coStack.push(opStack.pop());
					opStack.push(chars[i]);
				} else {
					opStack.push(chars[i]);
				}
			}
		}

		while (!opStack.isEmpty()) {
			coStack.push(opStack.pop());
		}

		// 计算
		Stack<Integer> calStack = new Stack<>();
		for (Character c : coStack) {
			if (checkChar(c)) {
				calStack.push(Character.getNumericValue(c));
			} else {
				int two = calStack.pop();
				int one = calStack.pop();
				calStack.push(calculate(c, one, two));
			}
		}

		return Integer.valueOf(calStack.pop());
	}

	/**
	 * compare operator
	 * 
	 * @param op
	 *            '+', '-', 'x', '/'
	 * @return 1: greater; 0: equal; -1: less
	 */
	private static int compareOp(char op1, char op2) {
		int opLevel1 = sortLevel(op1);
		int opLevel2 = sortLevel(op2);
		return opLevel1 - opLevel2;
	}

	private static int sortLevel(char op) {
		if (op == '+' || op == '-') {
			return 0;
		} else {
			return 1;
		}
	}

	private static boolean checkChar(char c) {
		if (c == '+' || c == '-' || c == 'x' || c == '/') {
			return false;
		} else {
			return true;
		}
	}

	private static int calculate(char op, int one, int two) {
		int result;
		switch (op) {
		case '+':
			result = one + two;
			break;
		case '-':
			result = one - two;
			break;
		case 'x':
			result = one * two;
			break;
		case '/':
			result = one / two;
			break;
		default:
			result = 0;
			break;
		}
		return result;
	}
}
